﻿@model WebPlatform.Models.LinksVM
@{
    ViewBag.Title = "友情链接";
    Layout = "~/Views/Shared/_ViewFormPage.cshtml";
}

@section head{
    
    <script src="/Scripts/AjaxFileUploaderV2.1/ajaxfileupload.js"></script>

    <script type="text/javascript">
        function save() {
            if ($("form").valid()) {
                $('form').ajaxSubmit({
                    beforeSubmit: function () {
                        $("#btnSave").off("click", save);
                    },
                    success: function (callback) {
                        if (callback) {
                            $.ligerDialog.success('保存成功', function (yes) {
                                self.location.href = "/Links/Edit?tid=@Model.Types";
                            });

                            }
                            else {
                                $("#btnSave").on("click", save);
                                $.ligerDialog.error('保存失败');
                            }
                    },
                    error: function (ex) {
                        $("#btnSave").on("click", save);
                        $.ligerDialog.error('保存失败');
                    }

                });
                }
            }

            $(function () {
                $("#btnSave").on("click", save);


                $("#btnUpload").click(function (e) {
                    e.preventDefault();
                    ajaxFileUpload();
                });

            });


            function ajaxFileUpload() {
                var dialog = $.ligerDialog.waitting('正在上传,请稍候...');
                $.ajaxFileUpload({
                    url: '/File/Upload',
                    secureuri: false,
                    fileElementId: 'imgFile',
                    dataType: 'json',
                    cache: false,
                    data: { dir: 'image', localUrl: '' },
                    success: function (data, status) {
                        if (typeof (data.error) !== 'undefined') {
                            if (data.error === 0) {
                                $("#productImage").attr("src", data.url);
                                $("#ImgUrl").val(data.url);
                            } else {
                                $.ligerDialog.error('上传出错:' + data.message);
                            }
                        }
                    },
                    error: function (data, status, e) {
                        $.ligerDialog.error('上传出错:' + e);
                    }
                    ,
                    complete: function (XMLHttpRequest, textStatus) {
                        dialog.close();
                    }
                })
                return false;
            }
    </script>
    @if (false)
    {
        <script src="../../Scripts/jquery-1.8.2.js"></script>
    }
    <style type="text/css">
    </style>
}
<div id="header" class="header">
    <h4>推广 -- 维护</h4>
</div>
@using (Html.BeginForm("Edit", "Links", FormMethod.Post))
{
    @Html.HiddenFor(model => model.CompanyId)
    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.Types)
    <div id="detail_forms">
        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                标题
            </div>
            <div class="formItem textItem">
                @Html.TextBoxFor(model => model.Title, new { @class = "texts" })
            </div>
            <div class="formItem msgItem">
                *
            </div>
        </div>

        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                图片
            </div>
            <div class="formItem textItem">
                <table border="0">
                    <tr>
                        <td style="height: 40px;">
                            <input type="file" id="imgFile" name="imgFile" />
                            <span class="buttons">
                                <a href="javascript:void(0);" id="btnUpload">上传</a>
                            </span>
                            <span>
                                图片尺寸：宽*高（150*60）
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div id="showImage">
                                <img title="点击上传图片" src='@Model.ImgUrl' style=" width:150px; height:60px; cursor:pointer;" alt="" id="productImage" />
                            </div>
                        </td>
                        <td style="vertical-align: bottom;">
                            <div style="width: 220px; margin-left: 10px; display: block">
                                @Html.HiddenFor(m => m.ImgUrl)
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="formItem msgItem">
            </div>
        </div>

        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                链接地址
            </div>
            <div class="formItem textItem">
                @Html.TextBoxFor(model => model.Url, new { @class = "texts" })
            </div>
            <div class="formItem msgItem">
                *
            </div>
        </div>



        <div id="btnContainer" class="formsItems">
            <div class="formItem labelItem">
                &nbsp;
            </div>
            <div class="formItem textItem">
                <a href="javascript:void(0);" id="btnSave">保存</a>
                <a href="/Links/Index?tid=@Model.Types" id="btnCancel">取消</a>
            </div>
            <div class="formItem">
            </div>
        </div>
        <div class="formsItems"></div>
    </div>
}
